<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Mauro Halfeld Feeds</title>
<style type="text/css" media="screen">
input {width:300px;}
input#emailSubject{width:600px;}
textarea {width:600px;height:400px;}
.fieldnew {width:495px;margin-left:30px;position:fixed;left:85px;}
</style>

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript" ></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/jquery-ui.min.js" type="text/javascript" ></script>
<script src="http://www.google.com/jsapi?key=ABQIAAAAUCMT6HwAXD3R_T01InnsdBSwAIn1hDF-fTEIYce5_WQ9kvYUTRRkmiQAXDqR_qlSDL10OYZENBSMHg" type="text/javascript"></script>

<script type="text/javascript" src="playerOndemand.js"></script>
<script type="text/javascript" src="detectBrowser.js"></script>
<script type="text/javascript" src="cookieMedia.js"></script>
<script type="text/javascript" src="opcoesPlayer.js"></script>

<script type="text/javascript" charset="utf-8">
    
	// Load the v2 of the Feed API
	var gmail = '';
	google.load('feeds', '1');

	//------------------------
	var entries = null;
	var entry = {link:'',title:'',content:'',contentSnippet:'',publishedDate:''};
	
	function yyyymmdd(entry,sep){
		var dt = new Date(entry.publishedDate);
		var d = dt.getDate(); d=(d < 10)?"0"+parseInt(d):parseInt(d);
		var m = dt.getMonth()+1; m=(m < 10)?"0"+parseInt(m):parseInt(m);
		var y = dt.getFullYear();
		return y+sep+m+sep+d;
	}
	
	function ddmmyy(entry){
		var dt = new Date(entry.publishedDate);
		var d = dt.getDate(); d=(d < 10)?"0"+parseInt(d):parseInt(d);
		var m = dt.getMonth()+1; m=(m < 10)?"0"+parseInt(m):parseInt(m);
		var y = dt.getFullYear()-2000;
		return d+"/"+m+"/"+y;
	}
	
	function ymd(entry){
		var dt = new Date(entry.publishedDate);
		var d = dt.getDate(); d=(d < 10)?"0"+parseInt(d):parseInt(d);
		var m = dt.getMonth()+1; m=(m < 10)?"0"+parseInt(m):parseInt(m);
		var y = "10";
		return y+""+m+""+d;
	}
	
	function getArticle(entry){
		var dt = new Date(entry.publishedDate);
		var yyyy = dt.getFullYear();
		return yyyy+"/colunas/halfeld_"+ymd(entry);
	}
	
	function play(i){
		var article = "";
		if (i>=0){
			if ((!entries)||(i<0||i>=entries.length))
				return;
			var article = getArticle(entries[i]);
		}
		var html = audioOndemand(article,600,70,'n');
		$("#player").html(html);
		$("#emailBody").focus();
	};
		
	function initText(){
		var ini = "Ola, respondo a e-mail recebido em cbndinheiro@cbn.com.br";
		$("#inputText").val(ini);	
	};
	
	function fillEmailForm(){
		var txt = $("#inputText").val();
		var to = "lilu532diqu@post.wordpress.com"
		var su = entry.title;		
		var urlPodcast="http://cbn.globoradio.globo.com/Player/player.htm?audio="+getArticle(entry);
		var linkPodcast='Transcrição autorizada do podcast de <a href="'+urlPodcast+'">Mauro Halfeld para CBN ('+ddmmyy(entry)+')</a>';
		var sig = "<b>Mauro Halfeld pra CBN</b>";
		var fin = '<i>Todos os comentários de Mauro Halfeld estão arquivados no site <a href="http://www.cbn.com.br">www.cbn.com.br</a></i>\n'
		var cmd = "[delay "+yyyymmdd(entry,'/')+"]\n[category financas]\n[tags orçamento,doméstico,finanças,pessoais,finanças pessoais,Mauro Halfeld,orçamento doméstico,Meu Dinheiro]";
		var bd = linkPodcast+"\n\n"+txt+"\n\n"+sig+"\n---\n"+fin+"\n"+cmd;	
		$("#emailTo").val(to);
		
		$("#hSubject").html(su);
		$("#emailSubject").val(su);
		
		$("#emailBody").val(bd);		
		var bdAsHtml = bd.replace(new RegExp( "\\n", "g" ),"<br>");
		$("#hBody").html(bdAsHtml);
	};
	
	function updateFormEntry(){
		$("#entryDate").val(yyyymmdd(entry,''));
		$("#entryTitle").val(entry.title);
		//$("#entryLink").val(entry.link);
		//$("#entryContent").val(entry.content);
		//$("#entryContentSnippet").val(entry.contentSnippet);			
	};
	
	function updateEntry(){
		var dtstr = $("#entryDate").val();
		if (dtstr.length>8)
			entry.publishedDate=$("#entryDate").val();
		else{
			dtstr=new String(dtstr);
			var yyyy = parseInt(dtstr.substr(0,4));
			var mm = parseInt(dtstr.substr(4,2));
			if (mm==0) mm=parseInt(dtstr.substr(5,1));
			var dd = parseInt(dtstr.substr(6,2));
			if (dd==0) dd = parseInt(dtstr.substr(7,1));
			var dt = new Date(yyyy,mm-1,dd);
			entry.publishedDate=dt;
		}
		entry.title=$("#entryTitle").val();
		//$("#entryLink").val(entry.link);
		//$("#entryContent").val(entry.content);
		//$("#entryContentSnippet").val(entry.contentSnippet);
		fillEmailForm();		
	};
	
	function select(i){
		if ((!entries)||(i<0||i>=entries.length))
			return;
		entry = entries[i];
		$("#selTitle").html('[ <a href="#" onclick="play('+i+');">Play</a> ] '+entry.title);
		initText();
		fillEmailForm();
		updateFormEntry();
	};
	
	function initialize() {
		var feed = new google.feeds.Feed("http://imagens.globoradio.globo.com/cbn/rss/comentaristas/maurohalfeld.xml");
		feed.setNumEntries(25);
		feed.load(function(result) {
			if (!result.error) {
				var html='';
				var container = document.getElementById("feed");
				entries=result.feed.entries;
				for (var i = 0; i < result.feed.entries.length; i++) {
					var entry = result.feed.entries[i];
					//----------------
					html+= '<div class="entry" onclick="select('+i+');">'+ddmmyy(entry)+' - '+ entry.title+"</div>";
				}
				html='<b>Select one of the feeds</b>'+html;
				$("#list").html(html);
				play(-1);
				$("#selTitle").html("N/A");
				$("#sendto").click(function(el){
					if (confirm("Are you sure?")){
						$("#compose").submit();
					}
				});
			}
		});
	}

    google.setOnLoadCallback(initialize);

</script>
  </head>
  <body>
	<div id="header" style="display:inline-block;">
		<div id="selection" style="display:inherit;">
			<div id="selTitle" style="width:600px;">Loading</div>
			<div id="player" style="width:600px;"></div>
			<textarea id="inputText" name="inputText" value=""></textarea>
			<br><a href="#" onclick="fillEmailForm();">Click to update email body text =></a><br><br>

			Date:<input type="text" id="entryDate" name="entryDate" value="" class="fieldnew"><br/>
			Title:<input type="text" id="entryTitle" name="entryTitle" value="" class="fieldnew"><br/>
			<!-- 
			Link:<input type="text" id="entryLink" name="entryLink" value="" class="fieldnew"><br/>
			Content:<input type="text" id="entryContent" name="entryContent" value="" class="fieldnew"><br/>
			ContentSnippet:<input type="text" id="entryContentSnippet" name="entryContentSnippet" value="" class="fieldnew"><br/>
			-->
			<a href="#" onclick="updateEntry();">Click to update the ENTRY object</a><br>
			
		</div>
		<div id="right" style="display:inherit;vertical-align:top;">
			<div id="list" style="display:inherit;"></div>
			<div id="emailform">
				<hr></hr>			
				<form id="compose" action="https://sites.google.com/a/macros/zoqui.com/exec?" method="POST" >
					<a id="sendto" href="#">Send To </a><input id="emailTo" type="text" name="to" value="">
					<input type="hidden" name="service" value="AKfycbxfdS2q0GV-p7Rnr5ukN87LS30xntzpT8c">
					<input type="hidden" id="emailBody" name="message" value="">		
					<input type="hidden" id="emailSubject" name="subject" value="">
				</form>
				<div id="msg" style="display:inherit;width:600px;">
					<b><div id="hSubject"></div></b>
					<div id="hBody"></div>
				</div>
			</div>
		</div>
	</div>
	<iframe src="#" id="fake-target" name="fake-target" style="width:0px; height:0px; border:0px;"></iframe>
  </body>
</html>